package entity;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;

import org.bson.types.ObjectId;

import com.google.code.morphia.annotations.Entity;
import com.google.code.morphia.annotations.Id;
import com.google.code.morphia.annotations.Indexed;

import util.StringHelper;

@SuppressWarnings("serial")
@Entity
public class Question implements Serializable {

	@Id
	private ObjectId id;
	@Indexed
	private Date lastUpdateDate;
	@Indexed
	private Date doc;
	@Indexed
	private String title;
	@Indexed
	private String alias;
	@Indexed
	private String url;
	@Indexed
	private String aliasAuthor;
	private String content;
	private String contentAnswer;
	private String aliasAuthorAnswer;
	@Indexed
	private String lang;
	@Indexed
	private ArrayList<String> tags = new ArrayList<String>();
	@Indexed
	private ArrayList<String> otherTags = new ArrayList<String>();
	@Indexed
	private int hadContent;

	public ObjectId getId() {
		return id;
	}

	public void setId(ObjectId id) {
		this.id = id;
	}

	public boolean isValid() {
		if (StringHelper.StringIsNullOrEmpty(this.alias)) {
			return false;
		}
		if (StringHelper.StringIsNullOrEmpty(this.content)) {
			return false;
		}
		if (StringHelper.StringIsNullOrEmpty(this.contentAnswer)) {
			return false;
		}
		if (StringHelper.StringIsNullOrEmpty(this.title)) {
			return false;
		}
		if (StringHelper.StringIsNullOrEmpty(this.url)) {
			return false;
		}
		return true;
	}

	public boolean isValidUrl() {
		if (StringHelper.StringIsNullOrEmpty(this.url)) {
			return false;
		}
		return true;
	}

	public String getSubContent() {
		String des = this.content.replaceAll("\\<.*?\\>", "");
		if (des.length() > 200) {
			des = des.substring(0, 200) + " ...";
		}
		return des;
	}

	public int countOtherTag() {
		int count = 0;
		for (String otherTag : this.otherTags) {
			if (otherTag != null) {
				count += 1;
			}
		}
		return count;
	}

	public int getHadContent() {
		return hadContent;
	}

	public void setHadContent(int hadContent) {
		this.hadContent = hadContent;
	}

	public Date getLastUpdateDate() {
		return lastUpdateDate;
	}

	public void setLastUpdateDate(Date lastUpdateDate) {
		this.lastUpdateDate = lastUpdateDate;
	}

	public Date getDoc() {
		return doc;
	}

	public void setDoc(Date doc) {
		this.doc = doc;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getAlias() {
		return alias;
	}

	public void setAlias(String alias) {
		this.alias = alias;
	}

	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}

	public String getAliasAuthor() {
		return aliasAuthor;
	}

	public void setAliasAuthor(String aliasAuthor) {
		this.aliasAuthor = aliasAuthor;
	}

	public String getContent() {
		return content;
	}

	public void setContent(String content) {
		this.content = content;
	}

	public String getContentAnswer() {
		return contentAnswer;
	}

	public void setContentAnswer(String contentAnswer) {
		this.contentAnswer = contentAnswer;
	}

	public String getAliasAuthorAnswer() {
		return aliasAuthorAnswer;
	}

	public void setAliasAuthorAnswer(String aliasAuthorAnswer) {
		this.aliasAuthorAnswer = aliasAuthorAnswer;
	}

	public String getLang() {
		return lang;
	}

	public void setLang(String lang) {
		this.lang = lang;
	}

	public ArrayList<String> getTags() {
		if (tags == null) {
			tags = new ArrayList<String>();
		}
		return tags;
	}

	public void setTags(ArrayList<String> tags) {
		this.tags = tags;
	}

	public ArrayList<String> getOtherTags() {
		if (otherTags == null) {
			otherTags = new ArrayList<String>();
		}
		return otherTags;
	}

	public void setOtherTags(ArrayList<String> otherTags) {
		this.otherTags = otherTags;
	}

}
